using System;
using System.Collections.Generic;
using System.Text;

namespace GearBlog.UnitTests.Services
{
	using System.IO;
	using Castle.MonoRail.Framework;
	using GearBlog.Web.Services;

	public class MockFileStorageService:IFileStorageService
	{
		private static List<string> _files = new List<string>();
		private static Dictionary<string,string> _storages=new Dictionary<string, string>();
		
		static MockFileStorageService()
		{
			_storages.Add("image","upload/img");

			_files.Add("file1.jpg");
			_files.Add("file2.png");
			
		}
		private static string BuildPath(params string[] pathElements)
		{
			string resultPath = pathElements[0];
			for (int i = 1; i < pathElements.Length - 1;i++ )
			{
				resultPath = Path.Combine(resultPath, pathElements[i]);

			}
			return resultPath;
		}

		public static List<string> Files
		{
			get { return _files; }
		}


		public static Dictionary<string, string> storages
		{
			get { return _storages; }
		}

		public string[] GetFiles(string storageKey, IRailsEngineContext context)
		{

			if (_storages.ContainsKey(storageKey))
				return BuildFileList(context, storageKey);
			else
				throw new ArgumentException(string.Format("Storage Key '{0}' not found.", storageKey), "storageKey");

				
		}

		public static string[] BuildFileList(IRailsEngineContext context, string storageKey )
		{
			List<string> fileList=new List<string>();

			foreach (string file in _files)
			{
				fileList.Add(BuildPath(context.ApplicationPhysicalPath, _storages[storageKey], file));
			}

			return fileList.ToArray();
		}

		public string GetPath(string storageKey, IRailsEngineContext context, string fileTitle)
		{
			return BuildPath(context.ApplicationPhysicalPath, _storages[storageKey], fileTitle);
		}

		public string GetUrl(string storageKey, IRailsEngineContext context, string fileTitle)
		{
			return BuildPath(context.ApplicationPath, _storages[storageKey], fileTitle);
		}

		public void StoreFile(string fileTitle, Stream inputStream)
		{
			throw new NotImplementedException();
		}
	}
}
